package app

import (
	"cr.org/config"
	"cr.org/db"
	"fmt"
	"github.com/gin-gonic/gin"
)

var app *App

type App struct {
	Server *gin.Engine
}

func init() {
	app = &App{}
}

func Run() error {
	// 初始化数据库
	db.InitDB()
	// 数据迁移
	db.Run()
	// 启动http服务
	app.Server = setupRoutes()
	fmt.Print(config.GlobalConfig)

	// 启动http服务
	app.Server = setupRoutes()
	if config.GlobalConfig.Server.Cert != "" && config.GlobalConfig.Server.Key != "" {
		return app.Server.RunTLS(config.GlobalConfig.Server.Addr, config.GlobalConfig.Server.Cert, config.GlobalConfig.Server.Key)
	} else {
		return app.Server.Run(config.GlobalConfig.Server.Addr)
	}
}
